package com.nuanshui.heatedloan.entity.cms.security;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.builder.ToStringBuilder;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.nuanshui.heatedloan.entity.IdEntity;

/**
 * 用户表
 */
@Entity
@Table(name = "cms_security_user")
public class User extends IdEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 真实姓名
	 */
	@Column(nullable = false, length = 32, unique = true, updatable = false)
	private String realname;

	/**
	 * 登陆用户名
	 */
	@Column(nullable = false, length = 16, unique = true, updatable = false)
	private String username;

	/**
	 * 密码
	 */
	@Column(nullable = false, length = 64)
	private String password;

	@Transient
	private String plainPassword;

	@Column(nullable = false, length = 32)
	private String salt;

	/**
	 * 电话
	 */
	@Column(length = 32)
	private String phone;

	/**
	 * E-mail
	 */
	@Column(length = 128)
	private String email;

	/**
	 * 使用状态disabled，enabled
	 */
	@Column(nullable = false, length = 16)
	private String status = "enabled";
	
	private Integer defaultUser;//是否是默认用户，比如admin  1 是

	/**
	 * 用户头像
	 */
	private String photo;

	@OneToMany(mappedBy = "user", cascade = CascadeType.ALL,fetch=FetchType.EAGER)
	@OrderBy("priority ASC")
	/*@JsonIgnore
	@JSONField(serialize=false)*/
	private List<UserRole> userRoles = Lists.newArrayList();

	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name = "orgId")
	@JsonIgnore
	@JSONField(serialize=false)
	private Organization organization;
	
	private String museumId;//可以管理的展馆

	private Date createTime;
	
	/**
	 * 用户昵称
	 */
	@Column(length = 30)
	private String nick;
	
	
	public Integer getDefaultUser() {
		return defaultUser;
	}

	public void setDefaultUser(Integer defaultUser) {
		this.defaultUser = defaultUser;
	}

	public String getMuseumId() {
		return museumId;
	}

	public void setMuseumId(String museumId) {
		this.museumId = museumId;
	}

	public String getRealname() {
		return realname;
	}

	public void setRealname(final String realname) {
		this.realname = realname;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(final String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(final String password) {
		this.password = password;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(final String status) {
		this.status = status;
	}

	public String getPlainPassword() {
		return plainPassword;
	}

	public void setPlainPassword(final String plainPassword) {
		this.plainPassword = plainPassword;
	}

	public String getSalt() {
		return salt;
	}

	public void setSalt(final String salt) {
		this.salt = salt;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(final String email) {
		this.email = email;
	}
	
	/*@JsonIgnore
	@JSONField(serialize=false)*/
	public List<UserRole> getUserRoles() {
		return userRoles;
	}
	
	public void setUserRoles(final List<UserRole> userRoles) {
		this.userRoles = userRoles;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(final String phone) {
		this.phone = phone;
	}
	
	@JsonIgnore
	@JSONField(serialize=false)
	public Organization getOrganization() {
		return organization;
	}
	
	public void setOrganization(final Organization organization) {
		this.organization = organization;
	}

	public String getPhoto() {
		return photo;
	}

	public void setPhoto(final String photo) {
		this.photo = photo;
	}
	
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(final Date createTime) {
		this.createTime = createTime;
	}

	

	public String getNick() {
		return nick;
	}

	public void setNick(String nick) {
		this.nick = nick;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
